package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    public void work(BookList bookList){
        System.out.println("新增图书...");
        System.out.println("请输入你要新增的图书的书名: ");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i=0;i<currentSize;i++){
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)){
                System.out.println("这本书已经存在，不进行新增...");
                System.out.println(book);
                return;
            }
        }

        //插入到后面位置
        System.out.println("请输入你要新增的图书的作者: ");
        String author = scanner.nextLine();

        System.out.println("请输入你要新增的图书的价格: ");
        int price = scanner.nextInt();

        scanner.nextInt();

        System.out.println("请输入你要新增的图书的类型: ");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);

        bookList.setBook(currentSize,book);

        bookList.setUsedSize(currentSize+1);
    }
}
